package com.youchuang.action.user;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.Indent;
import com.youchuang.bean.IndentItem;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.IndentService;

import net.sf.json.JSONArray;

@Namespace(value = "/user")
@ParentPackage("shopping-default")
public class SelectIndentAction extends BaseAction {

	private Logger logger = Logger.getLogger(SelectIndentAction.class.getSimpleName());
	private List<Indent> indents;
	private List<IndentItem> items;
	@Resource
	private IndentService indentService;

	@Action(value = "selectIndent", interceptorRefs = { @InterceptorRef(value = "loginStack") }, results = {
			@Result(name = ActionSupport.SUCCESS, location = "/WEB-INF/jsp/user/select_indent_list.jsp") })
	public String execute() throws Exception {
		logger.info("execution is execute");
		User user = (User) session.get(Constant.S_USER);
		String userId = user.getId();

		indents = indentService.findIndentByUserId(userId);
		items = indentService.findIndentItemByUserId(userId);

		logger.info("response json indents = " + JSONArray.fromObject(indents).toString());
		logger.info("response json items = " + JSONArray.fromObject(items).toString());
		return Constant.SUCCESS;
	}

	public List<Indent> getIndents() {
		return indents;
	}

	public void setIndents(List<Indent> indents) {
		this.indents = indents;
	}

	public List<IndentItem> getItems() {
		return items;
	}

	public void setItems(List<IndentItem> items) {
		this.items = items;
	}

}
